<?php

class Location extends Eloquent {
	protected $table;
	public $timestamps = false;
	
	/********************************************************************************
	 ******************************** PUBLIC FUNCTIONS ******************************
	 ********************************************************************************/
	
	/**
	 * ses the table for the model
	 */
	public function __construct() {
		$this->table = Helper::getDB ('gastro') . 'location';
	}
	
	
	/**********************************************************************
	 ************************** HAS MANY RELATIONS ************************
	 **********************************************************************/
	
	/**
	 * returns all managers for current location
	 * @param		array
	 */
	public function managers(){
		$this->belongsToMany('Manager', (Helper::getDB('gastro') . 'location_manager'), 'location_id', 'manager_id')->withPivot('isReservationManager');
	}
	
	
	public function openingDays(){
		$this->belongsToMany('OpeningDay', (Helper::getDB('gastro') . 'location_opening_time'), 'location_id', 'opening_day_id')->withPivot('open_from', 'open_until');
	}
	
	
	/**********************************************************************
	 ************************* BELONGS TO RELATIONS ***********************
	 **********************************************************************/
	
	/**
	 * returns the address
	 * @return		mixed
	 */
	public function address(){
		return $this->belongsTo('Address', 'address_id');
	}
	
	
	/**
	 * returns the customer company
	 * @return		mixed
	 */
	public function company(){
		return $this->belongsTo('CustomerCompany', 'company_id');
	}

}